home *** CD-ROM | disk | FTP | other *** search
- /************************************************************
- *
- * Created: Friday, March 8, 1991 11:24:46 AM
- * CNeoDatabase.h
- * C++ class implementation for the NeoAccess database class
- *
- *
- * Copyright © Neologic Systems 1992-1994. All Rights Reserved.
- * All rights reserved
- *
- *
- * The CNeoDatabase class is, in effect, an area manager. The area it manages is a
- * string of bytes that can be added to at the end. Access to the area however
- * is slower than accessing main memory. Information in the area can only be
- * accessed by allocating space in main memory. This main memory space needs
- * to be used as a cache of the database's contents.
- *
- ***********************************************************/
- #pragma once /* Include this file only once */
- #ifndef __CNeoDatabase__
- #define __CNeoDatabase__ 1
-
- #include "NeoTypes.h"
- #include CNeoDatabaseBaseH
-
- class CNeoMetaClass;
- class CNeoDatabase;
- class CNeoPersist;
- class CNeoIndexIterator;
- class CNeoPeer;
- class CNeoContainerStream;
- class CNeoTransaction;
-
- enum {kNeoUniqueIDBlockSize = 1000};
- enum {kNeoDatabaseCurrVersion = 0}; // current NeoAccess database version
- enum {kNeoDatabaseHeadSpace = (0x0100 + kNeoMinMark)}; // file space allocated for file header
- enum {kNeoDatabaseQuantum = 8}; // file space allocations are rounded to this quantum
- const long kNeoPurgeQuantum = 0x10000; // object cache purges are at least this quantum
-
- #define NeoDatabaseQuantumSpace(n) (((long)((n) + 7))&0x7FFFFFF8) // file space to really allocate
- #define NeoPurgeQuantumSpace(n) ((n) > kNeoPurgeQuantum ? (n) : kNeoPurgeQuantum)
-
-
- class CNeoDatabase : public CNeoDatabaseBase
- {
- public:
- /** Instance Methods **/
- CNeoDatabase(void);
- void INeoDatabase(void);
- virtual ~CNeoDatabase(void);
-
- virtual OSErr close(void);
- virtual OSErr create(void);
- virtual void flush(const Boolean aEntireDatabase);
- virtual OSErr open(const NeoPerms aPerms);
- virtual void reset(void);
-
- /** Access Methods **/
- virtual Boolean existsOnDisk(void) const;
- static CNeoDatabase *
- GetCurrentDatabase(void) {return gNeoDatabase;}
- long getLength(void) const;
- NeoMark getMark(void) const;
- virtual void getName(CNeoString &aName) const;
- virtual void getPathName(CNeoString &aName) const;
- CNeoContainerStream *
- getStream(const Boolean aStream = FALSE);
- virtual NeoID getUniqueID(void);
- NeoID getUniqueIDBlock(const long aCount);
- long getVersion(void) const {return fVersion;}
- virtual Boolean isDirty(void) const;
- Boolean isOpen(void) const;
- static void SetCurrentDatabase(CNeoDatabase *aDatabase);
- void setDirty(const Boolean aState = TRUE) {fDirty = aState;}
- void setFileSpec(const NeoFileSpec &aFileSpec);
- virtual void setLength(const long aLength);
- virtual void setMark(const NeoMark aMark);
- void setStream(CNeoContainerStream *aStream);
- void setVersion(const long aVersion);
-
- /** Macintosh Methods **/
- virtual OSType getCreator(void) const;
- virtual OSType getType(void) const;
- virtual void setCreator(const OSType aCreator);
- virtual void setType(const OSType aType);
-
- /** I/O Methods **/
- virtual void commit(const Boolean aCompress = FALSE, const Boolean aRemotely = FALSE, CNeoTransaction *aTransaction = nil);
-
- /** Object List Methods **/
- virtual void addObject(CNeoPersist *aObject);
- void enableTempRemoval(const Boolean aEnable = TRUE) {fRemoveTemps = aEnable;}
- virtual void * findObject(const NeoID aClassID, CNeoSelect *aKey, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil, const NeoLockType aLock = kNeoDefaultLock);
- CNeoIndexIterator * getIterator(const NeoID aClassID, CNeoSelect *aKey = nil, const Boolean aDeeply = FALSE, const Boolean aForward = TRUE);
- virtual void removeObject(CNeoPersist *aObject);
- virtual void removeTempObjects(const Boolean aAll);
-
- /** Free List Methods **/
- void freeSpace(const NeoMark aMark, const long aLength);
- Boolean getFastAllocation(void) const {return (Boolean)(fFastAlloc > 0);}
- NeoMark getSpace(const long aLength);
- NeoMark getSpaceBefore(const long aLength, const NeoMark aMark);
- void setFastAllocation(const Boolean aFast = TRUE);
-
- /** Class List Methods **/
- virtual Boolean addClass(CNeoMetaClass *aMeta);
- virtual long getClassCount(void);
- virtual long getObjectCount(const NeoID aClassID, const Boolean aDeeply);
- virtual void markClassTemporary(const NeoID aID, const Boolean aTemp);
-
- /** Iteration Methods **/
- void * doUntilClass(const NeoID aClassID, const Boolean aDeeply, NeoTestClassFunc aFunc = nil, void *aParam = nil);
- void * doUntilObject(CNeoPersist *aStart, const NeoID aClassID, const short aWhich, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil);
-
- NeoVersion getVersionUpdateType(void) const {return fVersionUpdateType;}
- void setUpdateType(const NeoVersion aType) {fVersionUpdateType = aType;}
-
- /** Concurrency Methods **/
- void lock(const NeoRefType /* aType */, long /* aMilliSeconds */ = kNeoWaitForever) {}
- void unlock(const NeoRefType /* aType */) {}
-
- /** MetaClass Creation Methods **/
- static void CreateDefaultMetaclasses(void);
-
- /** Purge Methods **/
- virtual Boolean purge(NeoSize &aNeeded);
- static Boolean PurgeCache(long aNeeded);
-
- /** Instance Variables **/
- protected:
- Boolean fRemoveTemps; // should temporary objects be removed when the database is opened?
- Boolean fDirty; // has file header changed since last written to database?
- Boolean fCommitting; // is the database being committed?
- public:
- Boolean fEmpty; // should the length be set ot zero on open?
- NeoFormat fFileFormat; // NeoAccess file format used in writing this file
-
- protected:
- long fFastAlloc; // need very fast file space allocation if > 0
- CNeoNode * fFreeList; // a handle to the first free list node in memory
- CNeoNode * fClassList; // a handle to the first class list node in memory
- long fLength; // length of database on disk before stream is open
-
- // File header data members
- long fVersion; // database version number
- NeoMark fFreeMark; // a file mark of the first free list node in memory
- NeoMark fClassMark; // a file mark of the first class list node in memory
- long fClassCount; // number of classes defined in this database
- NeoID fID; // next unique ID value of this database
-
- public:
- CNeoContainerStream *
- fNewStream; // For use during save as operations
- CNeoNode * fNewIndice; // index being added
- NeoVersion fVersionUpdateType; // Defines how object version #s are updated when committed
-
- protected:
- CNeoContainerStream *
- fStream;
-
- public:
- static short FPurgeLevel; // what to purge
- static long FPurgeMin; // minimum number of objects to purge at once
- static long FPurgeDelta; // minimum number of objects before calling MaxBlock
- static long FPurgeCount; // objects purged so far
- };
-
- class CNeoIdleChore : public CNeoChore {
- public:
- /** Instance Methods **/
- void remove(void);
- };
-
- class CNeoRemoveIdleChore : public CNeoChore {
- public:
- /** Instance Methods **/
- CNeoRemoveIdleChore(CNeoChore *aChore);
-
- virtual void Perform(long *maxSleep);
-
- protected:
- CNeoChore * fChore;
- };
- #endif
-